package com.elitetyc.customview.activity;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.elitetyc.customview.R;
import com.elitetyc.customview.custom.YybProgressView;

public class ProgressViewActivity extends AppCompatActivity {

    YybProgressView yyb_progress;
    private float progress = 0;

    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what==0){
                if (progress>100){
                    progress=0;
                }
                yyb_progress.setProgress(progress);
                progress++;
                handler.sendEmptyMessageDelayed(0,100);
            }
            if (msg.what==1){
                handler.removeMessages(0);
            }

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress_view);
        yyb_progress = findViewById(R.id.yyb_progress);
        yyb_progress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (yyb_progress.isStop())
                    handler.sendEmptyMessageDelayed(0,100);
                else  handler.sendEmptyMessage(1);
                yyb_progress.toggle();
            }
        });
        handler.sendEmptyMessageDelayed(0,100);
    }
}
